#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1010;
char mp[N][N];
int dx[] = { -1,1,0,0 };
int dy[] = { 0,0,-1,1 };
int n, scc, col[N][N];
bool vis[N * N];

void dfs(int x, int y) {
    col[x][y] = scc;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (mp[nx][ny] == '.' || col[nx][ny]) continue;
        dfs(nx, ny);
    }
}


int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> mp[i][j];
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (mp[i][j] == '.' || col[i][j]) continue;
            scc++;
            dfs(i, j);
        }
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (mp[i][j] == '.') continue;
            bool tag = true;
            for (int k = 0; k < 4; k++) {
                int x = i + dx[k], y = j + dy[k];
                if (mp[x][y] == '.') tag = false;
            }
            if (tag) {
                if (!vis[col[i][j]]) ans++;
                vis[col[i][j]] = true;
            }
        }
    }
    cout << scc - ans << endl;
    return 0;
}